
namespace FastFood.Business.Logic
{
	using System;
	using System.Collections.Generic;
	using EDOSwit.Entity;
    using FastFood.Business.Entities;
	using FastFood.DataAccess;
    using System.Data.Linq;

	/// <summary>
	/// Represents the Manager of Combos.
	/// </summary>
	[Serializable]
	public class CombosManager : Singleton<CombosManager>
	{
		#region Methods

		/// <summary>
		/// Selects all records from the Combos table.
		/// </summary>
		public IList<Combos> Listar()
		{
			try
			{
				return CombosData.Instancia.Listar();
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Selects a single record from the Combos table.
		/// </summary>
		public Combos Obtener(short comboID)
		{
			try
			{
                Combos combo = CombosData.Instancia.Obtener(comboID);
                combo.Combos_Productos = new EntitySet<Combos_Productos>();
                combo.Combos_Insumos = new EntitySet<Combos_Insumos>();
                combo.DetallesCombo = new List<DetalleCombo>();
                combo.Combos_Productos.AddRange(Combos_ProductosData.Instancia.ListarPorComboID(comboID));
                combo.Combos_Insumos.AddRange(Combos_InsumosData.Instancia.ListarPorComboID(comboID));

                foreach (Combos_Productos detalle in combo.Combos_Productos)
                {
                    detalle.Productos = ProductosManager.Instancia.Obtener(detalle.productoID);
                    DetalleCombo preparable = new DetalleCombo();
                    preparable.ConvertFromDetalleProductos(detalle);
                    combo.DetallesCombo.Add(preparable);
                }
                foreach (Combos_Insumos detalle in combo.Combos_Insumos)
                {
                    detalle.Insumos = InsumosData.Instancia.Obtener(detalle.insumoID);
                    DetalleCombo preparable = new DetalleCombo();
                    preparable.ConvertFromDetalleInsumos(detalle);
                    combo.DetallesCombo.Add(preparable);
                }

                return combo;
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Saves a record to the Combos table.
		/// </summary>
		public short Agregar(Combos combos)
		{
			try
			{
				return CombosData.Instancia.Agregar(combos);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Updates a record in the Combos table.
		/// </summary>
		public bool Modificar(Combos combos)
		{
			try
			{
				return CombosData.Instancia.Modificar(combos);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Combos table by its primary key.
		/// </summary>
		public bool Eliminar(short comboID)
		{
			try
			{
				return CombosData.Instancia.Eliminar(comboID);
			}
			catch (Exception) { throw; }
		}

		#endregion
	}
}
